module dgl.graphics.Color;

import str = tango.text.convert.Integer;

import dgl.Vector4;
import dgl.Vector3;

struct Color
{
	public uint r;

	public uint g;

	public uint b;

	public uint a;

	public static Color opCall( uint r, uint g, uint b )
	{
		return Color( r, g, b, 255 );
	}

	public static Color opCall( uint r, uint g, uint b, uint a )
	{
		Color ret;
		ret.r = r;
		ret.g = g;
		ret.b = b;
		ret.a = a;
		return ret;
	}
	
	public static Color opCall( Vector3 vector )
	{
		Color ret;
		ret.r = cast(int)( vector.x * 255 );
		ret.g = cast(int)( vector.y * 255 );
		ret.b = cast(int)( vector.z * 255 );
		ret.a = 255;
		return ret;
	}
	
	public static Color opCall( Vector4 vector )
	{
		Color ret;
		ret.r = cast(int)( vector.x * 255 );
		ret.g = cast(int)( vector.y * 255 );
		ret.b = cast(int)( vector.z * 255 );
		ret.a = cast(int)( vector.w * 255 );
		return ret;
	}

	public Vector3 toVector3()
	{
		return Vector3( r / 255f, g / 255f, b / 255f );
	}

	public Vector4 toVector4()
	{
		return Vector4( r / 255f, g / 255f, b / 255f, a / 255f );
	}
	
	public char[] toString()
	{
		char[] ret = "";
		ret ~= "{";
		ret ~= " R:" ~ str.toString( r );
		ret ~= " G:" ~ str.toString( g );
		ret ~= " B:" ~ str.toString( b );
		ret ~= " A:" ~ str.toString( a );
		ret ~= " }";
		return ret;
	}
	
	invariant
	{
		assert( r >= 0 && r <= 255 );
		assert( g >= 0 && g <= 255 );
		assert( b >= 0 && b <= 255 );
		assert( a >= 0 && a <= 255 );
	}
	
	public static Color white()
	{
		return Color( 255, 255, 255 );
	}
	
	public static Color cornflowerBlue()
	{
		return Color( 100, 149, 237 );
	}
}